//
//  AddViewController.m
//  UI11限时代码
//
//  Created by dllo on 15/11/24.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "AddViewController.h"
#import "Student.h"
#import "AddView.h"

@interface AddViewController ()<AddViewDelegate, UINavigationControllerDelegate,UIImagePickerControllerDelegate>

@property (nonatomic, retain) AddView *addV;

@end

@implementation AddViewController

- (void)dealloc
{
    [_addV release];
    [super dealloc];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    self.navigationItem.title = @"添加联系人";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(buttonAction:)];
    
    self.addV = [[AddView alloc] initWithFrame:self.view.frame];
    self.addV.delegate = self;
    [self.view addSubview:self.addV];
    [_addV release];
    
    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(buttonAction:)] autorelease];
    
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(buttonAction:)] autorelease];
    
}

- (void)headerImageHandle
{
    UIImagePickerController *imagePC = [[UIImagePickerController alloc] init];
    imagePC.delegate = self;
    [self presentViewController:imagePC animated:YES completion:^{
        
        
    }];
    [imagePC release];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    self.addV.imageV.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}

- (void)buttonAction:(UIBarButtonItem *)sender
{
    if (sender == self.navigationItem.rightBarButtonItem) {
        Student *stu = [[Student alloc] init];
        stu.name = self.addV.textF1.text;
        stu.sex = self.addV.textF2.text;
        stu.age = self.addV.textF3.text;
        stu.phone = self.addV.textF4.text;
        stu.image = self.addV.imageV.image;
        [self.delegate getStuInfo:stu];
        [stu release];
    }
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
